package com.yuzhi.master.system;


import com.yuzhi.common.core.domain.ApiResult;
import com.yuzhi.system.domain.Area;
import com.yuzhi.system.domain.AreaShort;
import com.yuzhi.system.service.IAreaService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 行政区划
 *
 * @author sunshine
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/area")
public class SysAreaController {

    private final IAreaService areaService;

    /**
     * 获取全国地区树
     */
    @GetMapping("/getAllTree")
    public List<AreaShort> getAllTree() {
        return this.areaService.getAllProvinces();
    }
    /**
     * 只获取全部省份
     */
    @GetMapping("/getOnlyProvinces")
    public ApiResult<List<Area>> getOnlyProvinces() {
        return ApiResult.ok(this.areaService.getOnlyProvinces());
    }
    /**
     * 根据省编码获取市区
     */
    @GetMapping("/getCityAndDistrict/{provinceCode}")
    public ApiResult<List<Area>> getCityAndDistrict(@PathVariable("provinceCode") String provinceCode) {
        return ApiResult.ok(this.areaService.getCityAndDistrictByProvince(provinceCode));
    }

    /**
     * 根据行政区编码获取完整所属地区信息(例如：320102 -> 江苏省南京市玄武区)
     */
    @GetMapping("/getCompleteInfoByCode/{areaCode}")
    public ApiResult<String> getCompleteInfoByCode(@PathVariable("areaCode") String areaCode) {
        return ApiResult.ok(this.areaService.getCompleteInfoByCodeData(areaCode));
    }
}
